package Panels;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import componentes.labtext;
import componentes.panelconfondo;

public class PanelGActor extends panelconfondo implements ActionListener {
	GridBagConstraints gbc;
	JButton bcontinuar,breset;
	int panel;
	labtext[] a = new labtext [6];
	int contador;
	String actores, titulop;
	
public PanelGActor(String titulo){
	super.setimagen("/recursos/cine1.jpg");
	panel = 1;
	this.dibujar();
	titulop=titulo;
}

public PanelGActor(int idsala,Date fechainicio,Date fechafin){
	super.setimagen("/recursos/cine1.jpg");
	panel = 2;
	this.dibujar();
}
	

	public void actionPerformed(ActionEvent e) {
		validar();
		for(int b=0;b<contador;b++){
			actores = "insert into actorpeli (titulo,nombre)values(\""+titulop+"\",\""+a[b+1].getText()+"\")";
			System.out.println(actores);
			try{
				componentes.ConexionBD.executeUpdateQuery(actores);
				JOptionPane.showMessageDialog(this,
					    "Base de datos actializada correctamente", 
					    "Message",
					    JOptionPane.INFORMATION_MESSAGE);

			}catch(Exception ex){		
				System.out.println(ex);
				JOptionPane.showMessageDialog(this,
					    "Error al actualizar los datos en la base de datos",
					    "Mensaje Error",
					    JOptionPane.ERROR_MESSAGE);
			} 	
		}
		
	}

public void dibujar(){
	this.setLayout(new GridBagLayout());
	a[1] = new labtext(" principal : ",1,3,15);
    gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
			GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(
					5, 5, 5, 5), 0, 0);
	this.add(a[1],gbc);
	
	a[2] = new labtext(" secundario : ",1,3,15);
    gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
			GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(
					5, 5, 5, 5), 0, 0);
	this.add(a[2],gbc);
	
	a[3] = new labtext(" secundario : ",1,3,15);
    gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
			GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(
					5, 5, 5, 5), 0, 0);
	this.add(a[3],gbc);
	
	a[4] = new labtext(" secundario : ",1,3,15);
    gbc = new GridBagConstraints(0, 3, 1, 1, 0, 0,
			GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(
					5, 5, 5, 5), 0, 0);
	this.add(a[4],gbc);
	
	a[5] = new labtext(" secundario : ",1,3,15);
    gbc = new GridBagConstraints(0, 4, 1, 1, 0, 0,
			GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(
					5, 5, 5, 5), 0, 0);
	this.add(a[5],gbc);
	
	bcontinuar = new JButton(" Continuar ");
    gbc = new GridBagConstraints(0, 9, 0, 0, 0, 0,
			GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(
					5, 5, 5, 5), 0, 0);
    bcontinuar.addActionListener(this);
	this.add(bcontinuar, gbc);
   
	breset = new JButton(" Resetear ");
    gbc = new GridBagConstraints(0, 9, 0, 0, 0, 0,
			GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(
					5, 5, 5, 5), 0, 0);
    breset.addActionListener(this);
	this.add(breset, gbc);
}
	
public void validar(){
	contador =0;
	if(this.a[1].validar()==true){
		contador++;
			}
	if(this.a[2].validar()==true){
		contador++;
			}
	if(this.a[3].validar()==true){
		contador++;
			}
	if(this.a[4].validar()==true){
		contador++;
			}
	
	System.out.println(contador);
	
}
	
}